package JUC.wn_syn_vlo;

public class syn类锁_Thread implements Runnable{
    static int x = 0;
    public  void incr(){
        synchronized (syn类锁_Thread.class){
                x++;
        }
    }
    @Override
    // syn可以加到run 但是 static不能加到官方run
    // -> 提出来有问题的i++ ?
    public void run() {
        for (int i = 0; i < 3000; i++)

            incr();
    }

    public static void main(String[] args) throws Exception{
        Thread t1 = new Thread(new syn类锁_Thread());
        t1.start();
        Thread t2 = new Thread(new syn类锁_Thread());
        t2.start();
        Thread t3 = new Thread(new syn类锁_Thread());
        t3.start();
        Thread t4 = new Thread(new syn类锁_Thread());
        t4.start();

        t1.join(); t2.join();t3.join();t4.join();
        for (int i = 0; i < 1000; i++) {
            System.out.println(i);
            Thread t = new Thread(new syn类锁_Thread());
            t.start();
            t.join();
        }
        System.out.println(x);
    }
}
